﻿using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Mask;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using Lamex.Base;
using Lamex.Common;
using Lamex.Interface;
using Lamex.Library;
using Lamex.Library.CommonClass;
using Lamex.mIE.Calculate;
using Lamex.mIE.DalServer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lamex.mIE.UI
{
    public partial class Frm_IE_PartFeature : frmBaseChild
    {
        DataTable dtProc_Type_Ctrl = new DataTable();
        Lamex.mIE.ucControls.ucShowPic ucShowPicList = null;
        Lamex.mIE.ucControls.ucShowPic_Ref ucShowPicList1 = null;
        int _RowHandle;//显示tooptip
        static DataTable dtResult_R = new DataTable();//定义全局清单列表
        static DataTable dtFeature = new DataTable();//工序特征表
        static DataTable dtFeature_Def = new DataTable();//特征清单表
        static DataTable dtFeature_Opt = new DataTable();//特征选项表
        static DataTable dtFeature_Opt_Lar = new DataTable();//选类特征选项表
        static DataTable dtPARTNO = new DataTable();//获取部件特征表部件号
        // static DataTable dtSize_List = new DataTable();//尺寸参数表
        static DataTable dtFeature_Values = Common.GetTable.GetCache_Feature();//保存特征值-保存时需初始化
        //static DataTable dtDWGNO_List = new DataTable();//产品类型选择后获取图纸号
        static DataTable dtRoutingList = new DataTable();
        static List<string> listTemp = new List<string>(); //获取上一次点击的值
        static string Feature_Value = "";
        static string Labor_Value = "";
        bool FLAG = true;//定义参考图纸是否显示
        static int FLAG_TYPE;//定义操作类型
        bool FLAG_CellValueChanged = true;//定义特征参数值是否有修改
        public Frm_IE_PartFeature()
        {
            InitializeComponent();
            rbPart_No_C.Checked = true;
            SetPanelControl3();
        }
        public Frm_IE_PartFeature(DataTable dt)
        {
            InitializeComponent();
            rbPart_No_C.Checked = true;
            SetPanelControl3();
            dtProc_Type_Ctrl = dt;
        }

        public Frm_IE_PartFeature(string DWG_NO, string Product_Type, string Part_No, string strFeature_Flag)
        {
            InitializeComponent();
            memoDWG_NO.Text = DWG_NO;
            txtProductItem.Text = Product_Type;

            if ((DWG_NO.Trim().Length <= 0 || DWG_NO.Trim() == "NIL") && Part_No.Length > 0)
            {
                rbBOM_U.Checked = true;
                FLAG_TYPE = 2;
                txtPart_No.Text = Part_No;
            }
            else
            {
                if (strFeature_Flag.Trim().Length > 0)
                {
                    rbPart_No_U.Checked = true;
                    FLAG_TYPE = 1;
                }
                else
                {
                    rbPart_No_C.Checked = true;
                    FLAG_TYPE = 3;
                }
            }
            SetPanelControl3();
        }
        private void Frm_IE_PartFeature_Load(object sender, EventArgs e)
        {
            try { this.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理

            Init();
            InitProductItem(dtProc_Type_Ctrl);
            //rbPart_No_C.Checked = true;
            //SetPanelControl3();
            GETPARTNO();
        }

        private void Frm_IE_PartFeature_Resize(object sender, EventArgs e)
        {
            SetSize();
        }
        public void SetSize()
        {
            int wight = this.panelControl3.Width;
            if (FLAG)
            {
                gc_CurrentPart.Width = wight / 2;
                gc_ReferencePart.Width = wight / 2;
            }
            else
            {
                gc_CurrentPart.Width = wight;
            }

        }
        public void Init()
        {
            //txtDWG_NO.Text = "";         
            txtProduct_Desc.Text = "";
            txtProduct_Desc.UcReadOnly = true;
            txtModleNo.Text = "";
            txtModleNo.UcReadOnly = true;
            gc_CurrentPart.Controls.Clear();
            gc_ReferencePart.Controls.Clear();
            gc_Routing_Combina.DataSource = new DataTable();
            gcPart_List.DataSource = new DataTable();
            gc_PartFeature.DataSource = new DataTable();
            gridControl1.DataSource = new DataTable();
            List<string> listTemp = new List<string>(); //获取上一次点击的值
            if (FLAG_TYPE == 1 || FLAG_TYPE == 3)
            {
                SetSize();
                gc_CurrentPart.Visible = true;
                gc_ReferencePart.Visible = true;
            }

        }

        //产品类型初始化
        public void InitProductItem(DataTable dt)
        {
            if (dt.Rows.Count > 0)
            {
                this.txtProductItem.Properties.Items.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.txtProductItem.Properties.Items.Add(dt.Rows[i]["PROD_CATEGORY"].ToString());
                }
                txtProductItem.SelectedIndex = 0;
                txtProductItem.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            }
            else
            {
                dt = BaseFactory<IE_Part_TaskList>.Instance.GetProductItem();
                this.txtProductItem.Properties.Items.Clear();
                if (dt.Rows.Count > 0)
                {
                    string[] list = dt.Rows[0]["FIELD_VALUE_OPTION"].ToString().Split(',');
                    foreach (var item in list)
                    {
                        this.txtProductItem.Properties.Items.Add(item);
                    }
                }
            }
        }

        //选择产品类型事件
        private void txtProductItem_UcTextChanged(object sender, EventArgs e)
        {
            Init();
            GetPartFeature();
            //InitDWGItem();
            gvPart_List_Click(null, null);
        }

        //单击任务清单
        private void gvPart_List_Click(object sender, EventArgs e)
        {
            if (dtResult_R.Rows.Count <= 0)
                return;
            //判断特征临时表是否有数据，若有则提示是否保存--Y保存/N清空
            if (dtFeature_Values.Rows.Count > 0)
            {
                if (ConfirmDelete() == DialogResult.Cancel)
                {
                    //必须清空特征值，因为数据存在内存中，不清空会导致数据叠加
                    dtFeature = new DataTable();
                    gc_PartFeature.DataSource = dtFeature;
                    gv_PartFeature.BestFitColumns();
                    dtFeature_Values = Common.GetTable.GetCache_Feature();
                    FLAG_CellValueChanged = true;
                }
                else
                {
                    DoSave(null);
                }
            }
            gc_ReferencePart.Controls.Clear();
            gc_CurrentPart.Controls.Clear();
            dtRoutingList = new DataTable();
            gc_Routing_Combina.DataSource = new DataTable();
            listTemp = new List<string>(); //获取上一次点击的值
            int iRow = gvPart_List.FocusedRowHandle;
            string DWG_No = gvPart_List.GetRowCellDisplayText(iRow, "DWG_NO").ToString();//标准图纸号
            string REF_PART = gvPart_List.GetRowCellDisplayText(iRow, "REF_DWG").ToString();//参考图纸号
            string Part_No = gvPart_List.GetRowCellDisplayText(iRow, "PART_NO").ToString();//部件编号

            if (FLAG_TYPE == 1 || FLAG_TYPE == 3)
            {
                //控制是否被锁定
                string name = Common.GetLock.GetUser(DWG_No).Trim();
                if (name.Length > 0)
                {
                    XtraMessageBox.Show("录入员-" + name + "：正在操作此图纸编号");
                    return;
                }
                //解锁当前录入员的操作图纸
                Common.GetLock.UnLock();

                //点击即锁定-当前图纸
                Common.GetLock.LockUser(DWG_No);
            }
            else
            {
                //控制是否被锁定
                string name = Common.GetLock.GetUser(Part_No).Trim();
                if (name.Length > 0)
                {
                    XtraMessageBox.Show("录入员-" + name + "：正在操作此部件编号");
                    return;
                }
                //解锁当前录入员的操作图纸
                Common.GetLock.UnLock();

                //点击即锁定-当前图纸
                Common.GetLock.LockUser(Part_No);
            }
            //显示图纸号在界面
            // txtDWG_NO.Text = DWG_No; 取消显示，不然会触发下拉事件
            //显示部件号在界面
            // txtPart_No.Text = Part_No;
            //显示描述在界面
            DataRow[] dr_Desc = dtResult_R.Select("PART_NO='" + Part_No + "'");
            if (dr_Desc.Length > 0)
            {
                txtProduct_Desc.Text = dr_Desc[0]["CN_DESC"].ToString();
                txtModleNo.Text = dr_Desc[0]["MODEL_NO"].ToString();
            }


            //按部件工艺路线显示    
            //dtRoutingList = Common.GetDWG_List.Dwg_List("IE_Part_Routing R JOIN IE_WorkCenter_Definition D ON R.PROCESS_CODE=D.PROCESS_CODE",
            //    "D.PROCESS_CODE,D.PROCESS_NAME AS PROCESS_NAMES", " and PART_NO='" + Part_No + "'");
            DataTable dtRoutingListTemp = Common.GetDWG_List.Dwg_List("IE_Part_Routing R JOIN IE_Routing_Combination C ON R.GROUP_CODE=C.GROUP_CODE",
                "C.ROUTING_CODE,C.ROUTING_DESC",
                "and R.PART_NO='" + Part_No + "' and R.DWG_NO='" + DWG_No + "'");
            if (dtRoutingListTemp.Rows.Count <= 0)
            {
                XtraMessageBox.Show("查不到此号码的工艺路线信息,请检查是否录入工艺路线！");
                return;
            }
            string[] strROUTING_CODE = dtRoutingListTemp.Rows[0]["ROUTING_CODE"].ToString().Split('_');
            string[] str_ROUTING_DESC = dtRoutingListTemp.Rows[0]["ROUTING_DESC"].ToString().Split('_');
            if (strROUTING_CODE.Length != str_ROUTING_DESC.Length)
            {
                XtraMessageBox.Show("工艺路线代码和工艺路线描述不一致，请检查！");
                return;
            }
            DataColumn dc1 = new DataColumn("PROCESS_CODE", typeof(string));
            DataColumn dc2 = new DataColumn("PROCESS_NAMES", typeof(string));
            dtRoutingList.Columns.Add(dc1);
            dtRoutingList.Columns.Add(dc2);
            for (int i = 0; i < strROUTING_CODE.Length; i++)
            {
                DataRow dr = dtRoutingList.NewRow();
                dr["PROCESS_CODE"] = strROUTING_CODE[i];
                dr["PROCESS_NAMES"] = str_ROUTING_DESC[i];
                dtRoutingList.Rows.Add(dr);
            }
            gc_Routing_Combina.DataSource = dtRoutingList;


            //得到特征清单表
            dtFeature_Def = Common.GetDWG_List.Dwg_List("IE_Feature_Definatian",
              "FEATURE_NAME,DISPLAY_SEQUENCE,FEAT_VALUE_FROM,VALUE_LOGIC,WORKTIME_LOGIC_CODE,FEATURE_DESC", "");

            //得到特征选项表
            dtFeature_Opt = Common.GetDWG_List.Dwg_List("IE_Feature_ValueOption",
           "FEATURE_NAME,FEAT_VALUE_OPTION,DEFAULT_VALUE", "");

            //得到特征选类表
            dtFeature_Opt_Lar = Common.GetDWG_List.Dwg_List("IE_Feature_ValueOption_Labor",
         "FEATURE_NAME,FEAT_VALUE_OPTION,LABOR_TIME", "  and  IS_DISABLE=0 ");

            // //得到尺寸参数表
            // dtSize_List = Common.GetDWG_List.Dwg_List("IE_Part_SizeParmList",
            //"[DWG_NO],[PART_NO],[WIDTH_1],[WIDTH_2],[DEPTH_1],[DEPTH_2],[THICK],[LENGTH],[WIDTH],[HEIGHT]",
            //" and PART_NO='" + Part_No + "'");

            if (FLAG_TYPE == 1 || FLAG_TYPE == 3)
            {
                SetSize();
                gc_ReferencePart.Visible = true;
                gc_CurrentPart.Visible = true;
                FLAG = true;
                //根据图纸号获取产品类型，因为不同的产品类型图纸路径不一致
                string sql_ProductType = @" select distinct PROD_CATEGORY from [dbo].[IE_Part_TaskList] where DWG_NO='" + DWG_No + "'";
                DataTable dt_ProductTemp = BaseBuildSql.GetDataTableBySql(sql_ProductType);
                //显示图片           
                var listPic = Common.GetShowPic.ShowPic_STD(dt_ProductTemp.Rows[0][0].ToString(), DWG_No, REF_PART, Part_No);

                //标准图纸
                if (listPic.Item1.Count > 0)
                {
                    ucShowPicList = new ucControls.ucShowPic();
                    ucShowPicList.LoadImageList(listPic.Item1);
                    ucShowPicList.Dock = DockStyle.Fill;
                    gc_CurrentPart.Controls.Add(ucShowPicList);
                }
                //参考图纸
                if (listPic.Item2.Count > 0)
                {
                    ucShowPicList1 = new ucControls.ucShowPic_Ref();
                    ucShowPicList1.LoadImageList(listPic.Item2);
                    ucShowPicList1.Dock = DockStyle.Fill;
                    gc_ReferencePart.Controls.Add(ucShowPicList1);
                }
                else
                {
                    gc_ReferencePart.Visible = false;
                    int wight = this.panelControl3.Width;
                    gc_CurrentPart.Width = wight;
                    FLAG = false;
                }
            }
            if (FLAG_TYPE == 2)
            {
                gridControl1.DataSource = new DataTable();
                if (Part_No.Length <= 0)
                    return;

                DataTable dt = new DataTable();
                string sql = "";
                if (Part_No.Substring(1, 2) == "96")
                {
                    sql = @"SELECT 
       [MATERIAL_NO]
      ,[COMPONENT]
      ,[DESCRIBES]
      ,[COMPONENT_QTY]
      ,[UNIT]
      ,[SINGLE_QTY]
      ,[DRAWING_NO]
      ,[CUTTING_SIZE]
      ,[Width]
      ,[Length]
      ,[Thiness]
      ,[MATERIAL_GROUP]
      ,[EDGE_CODE]
      ,[IMPORT_TS]
      ,[Version]
  FROM [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_SJR]
  where MATERIAL_NO='" + Part_No + "'";
                }
                else
                {
                    sql = @"SELECT 
       [MATERIAL_NO]
      ,[COMPONENT]
      ,[DESCRIBES]
      ,[COMPONENT_QTY]
      ,[UNIT]
      ,[SINGLE_QTY]
      ,[DRAWING_NO]
      ,[CUTTING_SIZE]
      ,[Width]
      ,[Length]
      ,[Thiness]
      ,[MATERIAL_GROUP]
      ,[EDGE_CODE]
      ,[IMPORT_TS]
      ,[Version]
  FROM [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_STD]
where MATERIAL_NO='" + Part_No + "'";
                }
                dt = BaseBuildSql.GetDataTableBySql(sql);
                gridControl1.DataSource = dt;
                //gridView1.BestFitColumns();
                gridView1.OptionsView.ColumnAutoWidth = false;
                this.gridView1.BestFitColumns();
            }
        }
        //单击工序代码
        private void gv_Routing_Combina_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dtCache = dtFeature_Values.Clone();//特征值缓存表
                //得到工序代码
                int iRow = gv_Routing_Combina.FocusedRowHandle;
                string StrPROCESS_CODE = gv_Routing_Combina.GetRowCellDisplayText(iRow, "PROCESS_CODE").ToString();//工序代码
                string StrPROCESS_Name = gv_Routing_Combina.GetRowCellDisplayText(iRow, "PROCESS_NAMES").ToString();//工序名称
                string StrPart_No = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "PART_NO").ToString();//部件编号
                string StrDWG_NO = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "DWG_NO").ToString();//图纸编号
                string StrREF_DWG = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "REF_DWG").ToString();//参考图纸
                string StrRREF_MAT = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "REF_MAT").ToString();//参考物料

                //若“IE_Part_FeatureList”存在数据，则显示出来
                //增加按参考物料|参考图纸查询是否存在数据
                DataTable dtFeatureList = new DataTable();
                dtFeatureList = Common.GetDWG_List.Dwg_List("IE_Part_FeatureList",
                  "DWG_NO,PART_NO,PROCESS_CODE,FEATURE_NAME,FEAT_VALUE,LABOR_VALUE", " and DWG_NO='" + StrDWG_NO + "' and PART_NO='" + StrPart_No + "' order by FEATURE_NAME asc ");

                //显示特征列表
                if (dtFeatureList.Rows.Count > 0 && FLAG_CellValueChanged)
                {
                    //当工艺路线变更时，出现与之前不同的工艺路线，则需要把新路线的特征带出来
                    if (dtFeatureList.Select("PROCESS_CODE='" + StrPROCESS_CODE + "'").Length <= 0)
                    {
                        //    dtFeature = Common.GetDWG_List.Dwg_List("IE_WorkCenter_Feature",
                        //"'' as DWG_NO,'' as PART_NO, PROCESS_CODE,FEATURE_NAME,'' as FEAT_VALUE,0 as LABOR_VALUE", " and PROCESS_CODE='" + StrPROCESS_CODE + "' order by FEATURE_NAME asc ");
                        //20191204 UPDATE BY BILL
                        dtFeature = Common.GetDWG_List.Dwg_List(@"[LamexMESManager].[dbo].[IE_WorkCenter_Feature] f
                    left join [dbo].[IE_Feature_ValueOption] v on f.FEATURE_NAME=v.FEATURE_NAME",
                        "'' as DWG_NO,'' as PART_NO, PROCESS_CODE,f.FEATURE_NAME,v.DEFAULT_VALUE as FEAT_VALUE,'' as LABOR_VALUE", " and PROCESS_CODE='" + StrPROCESS_CODE + "' order by f.FEATURE_NAME asc ");

                        if (dtFeature.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtFeature.Rows.Count; i++)
                            {
                                DataRow dr = dtFeatureList.NewRow();
                                dr["DWG_NO"] = StrDWG_NO;
                                dr["PART_NO"] = StrPart_No;
                                dr["PROCESS_CODE"] = dtFeature.Rows[i]["PROCESS_CODE"].ToString();
                                dr["FEATURE_NAME"] = dtFeature.Rows[i]["FEATURE_NAME"].ToString();
                                //dr["FEAT_VALUE"] = "";//20191204 UPDATE BY BILL                             
                                dr["FEAT_VALUE"] = dtFeature.Rows[i]["FEAT_VALUE"].ToString().Length > 0 ? dtFeature.Rows[i]["FEAT_VALUE"].ToString() : "";
                                dr["LABOR_VALUE"] = 0;
                                dtFeatureList.Rows.Add(dr);
                                //20191204 UPDATE BY BILL
                                if (dtFeature.Rows[i]["FEAT_VALUE"].ToString().Length > 0)
                                    UpdateTableData(StrDWG_NO, StrPart_No, dtFeature.Rows[i]["FEATURE_NAME"].ToString(), StrPROCESS_CODE, dtFeature.Rows[i]["FEAT_VALUE"].ToString());

                            }
                        }

                    }
                    dtFeature = dtFeatureList;//重新赋值,回刷CustomRowCellEdit方法
                    dtFeature_Values = dtFeatureList;
                }
                else if (!listTemp.Contains(StrPROCESS_CODE))
                {
                    //20191204 UPDATE BY BILL
                    dtFeature = Common.GetDWG_List.Dwg_List(@"[LamexMESManager].[dbo].[IE_WorkCenter_Feature] f
                    left join [dbo].[IE_Feature_ValueOption] v on f.FEATURE_NAME=v.FEATURE_NAME",
                    "'' as DWG_NO,'' as PART_NO, PROCESS_CODE,f.FEATURE_NAME,v.DEFAULT_VALUE as FEAT_VALUE,'' as LABOR_VALUE", " and PROCESS_CODE='" + StrPROCESS_CODE + "' order by f.FEATURE_NAME asc ");

                    #region 自动带出参考物料信息
                    //IED转IE+时特征表不保存空值，故需重新根据特征赋值
                    if (StrREF_DWG.Length > 0 && StrREF_DWG != "NIL")
                    {
                        if (StrRREF_MAT.Length > 0 && StrRREF_MAT != "NIL")
                        {
                            dtFeatureList = Common.GetDWG_List.Dwg_List("IE_Part_FeatureList",
                "DWG_NO,PART_NO,PROCESS_CODE,FEATURE_NAME,FEAT_VALUE,LABOR_VALUE", " and DWG_NO='" + StrREF_DWG + "' and PART_NO='" + StrRREF_MAT + "' order by FEATURE_NAME asc ");
                            //参考图纸和参考物料替换为图纸和部件号
                            if (dtFeatureList.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtFeature.Rows.Count; i++)
                                {
                                    string strFEAT_VALUE = "";
                                    double strLABOR_VALUE = 0;
                                    DataRow[] rows = dtFeatureList.Select("PROCESS_CODE='" + StrPROCESS_CODE + "' and FEATURE_NAME='" + dtFeature.Rows[i]["FEATURE_NAME"] + "'");
                                    if (rows.Length > 0)
                                    {
                                        strFEAT_VALUE = rows.CopyToDataTable().Rows[0]["FEAT_VALUE"].ToString();
                                        strLABOR_VALUE = Convert.ToDouble(rows.CopyToDataTable().Rows[0]["LABOR_VALUE"].ToString());
                                    }
                                    dtFeature.Rows[i]["FEAT_VALUE"] = strFEAT_VALUE;
                                    dtFeature.Rows[i]["LABOR_VALUE"] = strLABOR_VALUE;
                                }
                            }

                        }
                    }
                    else if (StrREF_DWG.Length <= 0 || StrREF_DWG == "NIL")
                    {
                        if (StrRREF_MAT.Length > 0 && StrRREF_MAT != "NIL")
                        {
                            dtFeatureList = Common.GetDWG_List.Dwg_List("IE_Part_FeatureList",
               "DWG_NO,PART_NO,PROCESS_CODE,FEATURE_NAME,FEAT_VALUE,LABOR_VALUE", " and DWG_NO='" + StrREF_DWG + "' and PART_NO='" + StrRREF_MAT + "' order by FEATURE_NAME asc ");
                            //参考图纸和参考物料替换为图纸和部件号
                            if (dtFeatureList.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtFeature.Rows.Count; i++)
                                {
                                    string strFEAT_VALUE = "";
                                    double strLABOR_VALUE = 0;
                                    DataRow[] rows = dtFeatureList.Select("PROCESS_CODE='" + StrPROCESS_CODE + "' and FEATURE_NAME='" + dtFeature.Rows[i]["FEATURE_NAME"] + "'");
                                    if (rows.Length > 0)
                                    {
                                        strFEAT_VALUE = rows.CopyToDataTable().Rows[0]["FEAT_VALUE"].ToString();
                                        strLABOR_VALUE = Convert.ToDouble(rows.CopyToDataTable().Rows[0]["LABOR_VALUE"].ToString());
                                    }
                                    dtFeature.Rows[i]["FEAT_VALUE"] = strFEAT_VALUE;
                                    dtFeature.Rows[i]["LABOR_VALUE"] = strLABOR_VALUE;
                                }
                            }
                        }
                    }
                    #endregion
                    DataTable dtHasTable = dtFeature.Clone();//特征值缓存表
                    if (dtFeature.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtFeature.Rows.Count; i++)
                        {
                            DataRow dr = dtHasTable.NewRow();
                            dr["DWG_NO"] = StrDWG_NO;
                            dr["PART_NO"] = StrPart_No;
                            dr["PROCESS_CODE"] = dtFeature.Rows[i]["PROCESS_CODE"].ToString();
                            dr["FEATURE_NAME"] = dtFeature.Rows[i]["FEATURE_NAME"].ToString();
                            // dr["FEAT_VALUE"] = "";//20191204 UPDATE BY BILL                          
                            dr["FEAT_VALUE"] = dtFeature.Rows[i]["FEAT_VALUE"].ToString().Length > 0 ? dtFeature.Rows[i]["FEAT_VALUE"].ToString() : "";
                            dr["LABOR_VALUE"] = Convert.ToDouble(0);
                            dtHasTable.Rows.Add(dr);

                        }
                        //判断各工序是否包含相同的特征值，若包含则不做更改
                        bool flag = true;
                        if (dtHasTable.Rows.Count > 0)
                        {
                            //使dtFeature_Values与dtHasTable行数相同
                            if (dtFeature_Values.Select("PROCESS_CODE='" + StrPROCESS_CODE + "'").Length > 0)
                            {
                                DataTable dtTemp1 = dtFeature_Values.Select("PROCESS_CODE='" + StrPROCESS_CODE + "'").CopyToDataTable();

                                for (int i = 0; i < dtTemp1.Rows.Count; i++)
                                {
                                    for (int j = 0; j < dtHasTable.Rows.Count; j++)
                                    {
                                        if (dtTemp1.Rows[i]["FEATURE_NAME"].ToString() == dtHasTable.Rows[j]["FEATURE_NAME"].ToString() &&
                                            dtTemp1.Rows[i]["PROCESS_CODE"].ToString() == dtHasTable.Rows[i]["PROCESS_CODE"].ToString())
                                        {
                                            flag = false;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            if (dtHasTable.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtHasTable.Rows.Count; i++)
                                {
                                    DataRow dr = dtFeature_Values.NewRow();
                                    dr["DWG_NO"] = StrDWG_NO;
                                    dr["PART_NO"] = StrPart_No;
                                    dr["PROCESS_CODE"] = dtHasTable.Rows[i]["PROCESS_CODE"].ToString();
                                    dr["FEATURE_NAME"] = dtHasTable.Rows[i]["FEATURE_NAME"].ToString();
                                    // dr["FEAT_VALUE"] = "";//20191204 UPDATE BY BILL                                  
                                    dr["FEAT_VALUE"] = dtHasTable.Rows[i]["FEAT_VALUE"].ToString().Length > 0 ? dtHasTable.Rows[i]["FEAT_VALUE"].ToString() : "";
                                    dr["LABOR_VALUE"] = Convert.ToDouble(0);
                                    dtFeature_Values.Rows.Add(dr);
                                    //20191204 UPDATE BY BILL
                                    if (dtFeature.Rows[i]["FEAT_VALUE"].ToString().Length > 0)
                                        UpdateTableData(StrDWG_NO, StrPart_No, dtHasTable.Rows[i]["FEATURE_NAME"].ToString(), StrPROCESS_CODE, dtHasTable.Rows[i]["FEAT_VALUE"].ToString());

                                }
                                //获取上一次点击的值
                                listTemp.Add(StrPROCESS_CODE);
                            }
                        }
                    }
                    //针对布棉工序特殊触发工时
                    if (StrPROCESS_CODE == "S02" || StrPROCESS_CODE == "S03")
                    {

                        //更新Datatable值
                        DataTable dtTemp1 = dtFeature_Values.Select("PROCESS_CODE='" + StrPROCESS_CODE + "'").CopyToDataTable();
                        for (int j = 0; j < dtTemp1.Rows.Count; j++)
                        {
                            double temp = 0;
                            string FeatValueTemp = "";
                            string StrFeature_Name = dtTemp1.Rows[j]["FEATURE_NAME"].ToString();
                            DataTable dtTemp = Calculate.LGC_VAL_S02_S03.GetSeat_Value(StrPart_No, StrFeature_Name, out temp);
                            if (temp > 0)
                                FeatValueTemp = temp.ToString();

                            DataRow[] foundIndex1 = dtFeature_Values.Select("FEATURE_NAME='" + StrFeature_Name + "'");

                            foreach (DataRow row in foundIndex1)
                            {
                                dtFeature_Values.Rows.Remove(row);
                            }
                            DataRow dr = dtFeature_Values.NewRow();
                            dr["DWG_NO"] = StrDWG_NO;
                            dr["PART_NO"] = StrPart_No;
                            dr["PROCESS_CODE"] = StrPROCESS_CODE;
                            dr["FEATURE_NAME"] = StrFeature_Name;
                            dr["FEAT_VALUE"] = FeatValueTemp;
                            dr["LABOR_VALUE"] = Convert.ToDouble(0);
                            dtFeature_Values.Rows.Add(dr);
                            UpdateTableData(StrDWG_NO, StrPart_No, StrFeature_Name, StrPROCESS_CODE, FeatValueTemp);
                        }
                    }

                }

                //重新加载已录特征值
                DataRow[] foundIndex = dtFeature_Values.Select("PROCESS_CODE='" + StrPROCESS_CODE + "'");
                foreach (DataRow row in foundIndex)
                {
                    dtCache.ImportRow(row);
                }
                //dtCache.DefaultView.Sort = "FEATURE_NAME asc";
                //一个DataTable按另一个的某列排序
                DataTable dataTable = LinqSortDataTable(dtCache, dtFeature_Def);

                gc_PartFeature.DataSource = dataTable;
                gv_PartFeature.BestFitColumns();
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        //动态加载特征值
        private void gv_PartFeature_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            string StrDWG_No = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "DWG_NO").ToString();//标准图纸号      
            string StrPart_No = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "PART_NO").ToString();//部件编号


            if (e.Column.FieldName == "FEAT_VALUE")
            {
                string StrPROCESS_CODE = gv_Routing_Combina.GetRowCellDisplayText(gv_Routing_Combina.FocusedRowHandle, "PROCESS_CODE").ToString();//工序代码

                if (dtFeature_Values.Select("PROCESS_CODE='" + StrPROCESS_CODE + "'").Length <= 0)
                    return;
                DataTable dtTemp = dtFeature_Values.Select("PROCESS_CODE='" + StrPROCESS_CODE + "'").CopyToDataTable();
                //DataView dv = new DataView(dtTemp);
                //dv.Sort = "FEATURE_NAME asc";
                //dtTemp = dv.ToTable();
                dtTemp = LinqSortDataTable(dtTemp, dtFeature_Def);
                if (dtTemp.Rows.Count > 0)//dtFeature_Values dtFeature
                {
                    for (int i = 0; i < dtTemp.Rows.Count; i++)//dtFeature_Values dtFeature
                    {

                        var list = Common.GetFeat_Value.Feat_Value_From(dtFeature_Def, dtFeature_Opt, dtFeature_Opt_Lar, dtTemp.Rows[i]["FEATURE_NAME"].ToString(), StrDWG_No, StrPart_No, StrPROCESS_CODE);
                        if (e.RowHandle == i)
                        {
                            if (list.Item1 == "text")
                            {
                                //RepositoryItemTextEdit riMaskedTextEdit = new RepositoryItemTextEdit();
                                //riMaskedTextEdit.Mask.MaskType = MaskType.RegEx;
                                //riMaskedTextEdit.Mask.UseMaskAsDisplayFormat = true;
                                //riMaskedTextEdit.Mask.SaveLiteral = false;
                                //riMaskedTextEdit.Mask.EditMask = list.Item2;
                                //e.RepositoryItem = riMaskedTextEdit;
                                Feature_Value = list.Item2;
                                RepositoryItemTextEdit riMaskedTextEdit = NullEdit;
                                e.RepositoryItem = riMaskedTextEdit;

                                //删除原有数据,重新赋值给【值】这列
                                DataRow[] foundIndex = dtFeature_Values.Select("FEATURE_NAME='" + dtTemp.Rows[i]["FEATURE_NAME"].ToString() + "' and PROCESS_CODE='" + StrPROCESS_CODE + "' ");
                                foreach (DataRow row in foundIndex)
                                {
                                    dtFeature_Values.Rows.Remove(row);
                                }
                                DataRow dr = dtFeature_Values.NewRow();
                                dr["DWG_NO"] = StrDWG_No;//"";
                                dr["PART_NO"] = StrPart_No;//"";
                                dr["PROCESS_CODE"] = StrPROCESS_CODE;
                                dr["FEATURE_NAME"] = dtTemp.Rows[i]["FEATURE_NAME"].ToString();
                                dr["FEAT_VALUE"] = list.Item2;
                                dr["LABOR_VALUE"] = Math.Round(Convert.ToDouble(list.Item3), 2);
                                dtFeature_Values.Rows.Add(dr);
                            }
                            if (list.Item1 == "select")
                            {
                                RepositoryItemComboBox cb = new RepositoryItemComboBox();
                                string[] Values = list.Item2.Split('/');
                                foreach (var item in Values)
                                {
                                    cb.Items.Add(item);
                                }
                                cb.TextEditStyle = TextEditStyles.DisableTextEditor;//设置不可编辑
                                e.RepositoryItem = cb;
                            }
                            if (list.Item1 == "combobox")
                            {
                                RepositoryItemComboBox cb = new RepositoryItemComboBox();
                                string[] Values = list.Item2.Split(';');
                                foreach (var item in Values)
                                {
                                    cb.Items.Add(item);
                                }
                                cb.TextEditStyle = TextEditStyles.DisableTextEditor;//设置不可编辑
                                e.RepositoryItem = cb;

                            }
                        }
                    }
                }
            }

        }


        //保存缓存特征值
        private void gv_PartFeature_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            //得到图纸号/部件号工序代码/工序名称/特征名称/特征值
            string StrDWG_No = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "DWG_NO").ToString();//标准图纸号      
            string StrPart_No = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "PART_NO").ToString();//部件编号
            string StrPROCESS_CODE = gv_Routing_Combina.GetRowCellDisplayText(gv_Routing_Combina.FocusedRowHandle, "PROCESS_CODE").ToString();//工序代码
            // string StrPROCESS_Name = gv_Routing_Combina.GetRowCellDisplayText(gv_Routing_Combina.FocusedRowHandle, "PROCESS_NAMES").ToString();//工序名称
            string StrFeature_Name = gv_PartFeature.GetRowCellDisplayText(gv_PartFeature.FocusedRowHandle, "FEATURE_NAME").ToString();//特征名称
            string StrFeature_Values = gv_PartFeature.GetRowCellDisplayText(gv_PartFeature.FocusedRowHandle, "FEAT_VALUE").ToString();//特征值
            //跟进特征名称查出值逻辑
            string VALUE_LOGIC = "";
            DataRow[] dr = dtFeature_Def.Select("FEATURE_NAME='" + StrFeature_Name + "'");
            if (dr.Length > 0)
            {
                VALUE_LOGIC = dr.CopyToDataTable().Rows[0]["VALUE_LOGIC"].ToString();
            }

            //特征针对电车车缝计算V值
            if (StrFeature_Name == "S02_电车车缝")
            {
                double temp = 0;
                DataTable dtTemp = Calculate.LGC_VAL_S02_S03.GetSeat_Value(StrPart_No, StrFeature_Name, out temp);
                StrFeature_Values = temp.ToString();
            }
            if (VALUE_LOGIC == "LGC_VAL_T01_BUMPING")//(StrFeature_Name == "T01_数冲凸包")
            {
                double temp = 0;
                temp = Calculate.LGC_VAL_T01_BUMPING.LGC_VAL_T01_BUMPING_VALUE(StrDWG_No, StrPart_No, StrFeature_Values);
                StrFeature_Values = temp.ToString();
            }
            if (VALUE_LOGIC == "LGC_VAL_T03_WELDING")//(StrFeature_Name == "T03_焊接点数")
            {
                double temp = 0;
                temp = Calculate.LGC_VAL_T03_WELDING.LGC_VAL_T03_WELDING_VALUE(StrDWG_No, StrPart_No, StrFeature_Values);
                StrFeature_Values = temp.ToString();
            }
            if (StrFeature_Name == "P31_电子锯开料")
            {
                DataTable dtSize = BaseBuildSql.GetDataTableBySql(" select WIDTH,HEIGHT FROM IE_Part_SizeParmList where PART_NO='" + StrPart_No + "'");
                if (dtSize.Rows.Count > 0)
                {
                    if (dtSize.Rows[0]["WIDTH"].ToString().Trim().Length <= 0 && dtSize.Rows[0]["HEIGHT"].ToString().Trim().Length <= 0)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("尺寸参数【长】或【宽】未维护", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("尺寸参数未维护", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            UpdateTableData(StrDWG_No, StrPart_No, StrFeature_Name, StrPROCESS_CODE, StrFeature_Values);
            FLAG_CellValueChanged = false;
            gv_Routing_Combina_Click(null, null);//回刷gridcontrol
        }

        public void UpdateTableData(string StrDWG_No, string StrPart_No, string StrFeature_Name, string StrPROCESS_CODE, string StrFeature_Values)
        {
            string StrFeature_ValuesTemp = "";
            //跟进特征名称查出值逻辑【需要再次查询，因为该方法多个地方用到，不能作为参数】
            string VALUE_LOGIC = "";
            DataRow[] dr1 = dtFeature_Def.Select("FEATURE_NAME='" + StrFeature_Name + "'");
            if (dr1.Length > 0)
            {
                VALUE_LOGIC = dr1.CopyToDataTable().Rows[0]["VALUE_LOGIC"].ToString();
            }
            if (StrFeature_Name == "S02_电车车缝" || VALUE_LOGIC == "LGC_VAL_T01_BUMPING" || VALUE_LOGIC == "LGC_VAL_T03_WELDING")
            {
                StrFeature_ValuesTemp = gv_PartFeature.GetRowCellDisplayText(gv_PartFeature.FocusedRowHandle, "FEAT_VALUE").ToString();//特征值
            }
            //保存临时时间到Datatable
            //删除原有数据
            if (dtFeature_Values.Rows.Count > 0)
            {
                DataRow[] foundIndex = dtFeature_Values.Select("FEATURE_NAME='" + StrFeature_Name + "' and PROCESS_CODE='" + StrPROCESS_CODE + "'");
                foreach (DataRow row in foundIndex)
                {
                    dtFeature_Values.Rows.Remove(row);
                }

            }
            double strValue_1 = 0;
            DataRow dr = dtFeature_Values.NewRow();
            dr["DWG_NO"] = StrDWG_No;
            dr["PART_NO"] = StrPart_No;
            dr["PROCESS_CODE"] = StrPROCESS_CODE;
            dr["FEATURE_NAME"] = StrFeature_Name;
            dr["FEAT_VALUE"] = StrFeature_ValuesTemp != "" ? StrFeature_ValuesTemp : StrFeature_Values;

            //转换特征值
            if (StrFeature_Values.Contains("?"))
            {
                if (Common.GetFeat_Value.IsNumber(IELogicHelper.GetLogicValue(StrDWG_No, StrPart_No, StrFeature_Values)))
                    strValue_1 = Convert.ToDouble(IELogicHelper.GetLogicValue(StrDWG_No, StrPart_No, StrFeature_Values));
            }
            else if (StrFeature_Values == "LGC_VAL_T01_BUMPING")
            {
                strValue_1 = Calculate.LGC_VAL_T01_BUMPING.LGC_VAL_T01_BUMPING_VALUE(StrDWG_No, StrPart_No, StrFeature_Name);
            }
            else if (StrFeature_Values == "LGC_VAL_T03_WELDING")
            {
                strValue_1 = Calculate.LGC_VAL_T03_WELDING.LGC_VAL_T03_WELDING_VALUE(StrDWG_No, StrPart_No, StrFeature_Name);
            }
            else
            {
                if (Common.GetFeat_Value.IsNumber(StrFeature_Values))
                    strValue_1 = Convert.ToDouble(StrFeature_Values);

            }
            //计算工时
            //D034单独计算-不在此计算工时
            if (StrPROCESS_CODE == "D34")
            {
                dr["LABOR_VALUE"] = 0;
            }
            else
            {
                #region 当特征值为0时，工时为0
                if (strValue_1 == 0 && (StrFeature_Values.Trim().Length <= 0 || StrFeature_Values.Trim() == "0"))
                    dr["LABOR_VALUE"] = 0;
                #endregion
                else
                {
                    DataTable dtFeature = BaseBuildSql.GetDataTableBySql(" select * from IE_Feature_Definatian where 1=1 and FEATURE_NAME = '" + StrFeature_Name + "'");
                    if (dtFeature.Rows.Count != 0)
                    {
                        if (dtFeature.Rows[0][0] != null)
                        {
                            string strValues = dtFeature.Rows[0]["WORKTIME_LOGIC_CODE"].ToString();
                            if (strValues.Contains("?"))
                                dr["LABOR_VALUE"] = Math.Round(Convert.ToDouble(IELogicHelper.GetLogicValue(StrDWG_No, StrPart_No, StrFeature_Values.Trim())), 2);
                            else if (strValues == "LGC_TIM_LABOR")
                                dr["LABOR_VALUE"] = Math.Round(LGC_TIM_LABOR.LGC_TIM_LABOR_VALUE(StrFeature_Name, StrFeature_Values), 2);
                            else if (strValues == "LGC_TIM_T02_BENDING")
                                dr["LABOR_VALUE"] = Math.Round(LGC_TIM_T02_BENDING.LGC_TIM_T02_BENDING_VALUE(StrDWG_No, StrPart_No, StrFeature_Values), 2);
                            else if (strValues == "LGC_TIM_VTA")
                                dr["LABOR_VALUE"] = Math.Round(LGC_TIM_VTA.LGC_TIM_VTA_VALUE(StrDWG_No, StrPart_No, StrFeature_Name, StrFeature_ValuesTemp, strValue_1), 2);
                            else if (strValues == "LGC_TIM_D28_SAW")
                                dr["LABOR_VALUE"] = Math.Round(LGC_TIM_D28_SAW.LGC_TIM_D28_SAW_VALUE(StrDWG_No, StrPart_No, StrFeature_Values), 2);
                            else if (strValues == "LGC_TIM_D29_SAW")
                                dr["LABOR_VALUE"] = Math.Round(LGC_TIM_D29_SAW.LGC_TIM_D29_SAW_VALUE(StrDWG_No, StrPart_No, StrFeature_Values), 2);
                            else if (strValues == "LGC_TIM_D31_SAW")
                                dr["LABOR_VALUE"] = Math.Round(LGC_TIM_D31_SAW.LGC_TIM_D31_SAW_VALUE(StrDWG_No, StrPart_No, StrFeature_Values), 2);
                            //else if (strValues == "LGC_TIM_D42_SAW")
                            //    dr["LABOR_VALUE"] = 0;
                            else
                                dr["LABOR_VALUE"] = strValues;
                        }
                    }
                }
            }
            dtFeature_Values.Rows.Add(dr);
            //dtFeature_Values.DefaultView.Sort = "FEATURE_NAME asc";
            dtFeature_Values = LinqSortDataTable(dtFeature_Values, dtFeature_Def);
        }

        //保存
        public override void DoSave(IButtonInfo sender)
        {
            try
            {
                #region 按钮权限
                if (!BuildSqlHelper.IsExistList("IE_Part_FeatureList", "LamexMESManager")) return;
                #endregion
                if (dtFeature_Values.Rows.Count > 0)
                {
                    //string StrDWG_No = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "DWG_NO").ToString();//标准图纸号                  
                    //string StrPart_No = gvPart_List.GetRowCellDisplayText(gvPart_List.FocusedRowHandle, "PART_NO").ToString();//部件编号
                    string StrDWG_No = dtFeature_Values.Rows[0]["DWG_NO"].ToString();//有可能是空值
                    string StrPart_No = dtFeature_Values.Rows[0]["PART_NO"].ToString();//有可能是空值

                    DataTable dtTempList = Common.GetTable.GetTable_Feature();
                    //获取工序所有特征-避免【dtFeature_Values】为空的没有保存到
                    List<string> list = new List<string>();
                    List<string> list1 = new List<string>();
                    List<string> list2 = new List<string>();
                    StringBuilder sbFilter1 = new StringBuilder();
                    for (int i = 0; i < dtRoutingList.Rows.Count; i++)
                    {
                        list.Add(dtRoutingList.Rows[i]["PROCESS_CODE"].ToString());
                    }
                    if (list.Count > 0)
                        sbFilter1.AppendFormat(@" AND PROCESS_CODE IN ('{0}')", string.Join("','", list.ToArray()));
                    DataTable dtTemp = Common.GetDWG_List.Dwg_List("IE_WorkCenter_Feature", "PROCESS_CODE,FEATURE_NAME", sbFilter1.ToString());
                    if (dtTemp.Rows.Count > 0)
                    {
                        for (int k = 0; k < dtTemp.Rows.Count; k++)
                        {
                            list1.Add(dtTemp.Rows[k]["FEATURE_NAME"].ToString());
                        }
                    }
                    for (int j = 0; j < dtFeature_Values.Rows.Count; j++)
                    {
                        list2.Add(dtFeature_Values.Rows[j]["FEATURE_NAME"].ToString());
                    }
                    //取得list1与list2的差集-即把所有特征加上到特征表
                    IEnumerable<string> exceptLs = list1.Except(list2);
                    foreach (var item in exceptLs)
                    {
                        DataRow dr = dtFeature_Values.NewRow();
                        dr["DWG_NO"] = StrDWG_No;
                        dr["PART_NO"] = StrPart_No;
                        dr["PROCESS_CODE"] = dtTemp.Select("FEATURE_NAME='" + item + "'").CopyToDataTable().Rows[0]["PROCESS_CODE"].ToString();
                        dr["FEATURE_NAME"] = item;
                        dr["FEAT_VALUE"] = 0;
                        dtFeature_Values.Rows.Add(dr);
                    }

                    //工作中心对应特征全部为空时不保存
                    bool flag_save = true;
                    int s1 = 0;
                    DataTable Dis_Temp1 = dtFeature_Values.DefaultView.ToTable(true, new[] { "PROCESS_CODE" });
                    for (int i = 0; i < Dis_Temp1.Rows.Count; i++)
                    {
                        if (flag_save)
                        {
                            DataTable dt_temp = dtFeature_Values.Select("PROCESS_CODE='" + Dis_Temp1.Rows[i]["PROCESS_CODE"].ToString() + "'").CopyToDataTable();
                            for (int j = 0; j < dt_temp.Rows.Count; j++)
                            {
                                if (!string.IsNullOrEmpty(dt_temp.Rows[j]["FEAT_VALUE"].ToString().Trim()))
                                {
                                    s1 = 0;
                                    break;
                                }
                                else
                                {
                                    s1++;
                                    if (s1 == dt_temp.Rows.Count)
                                        flag_save = false;
                                }
                            }
                        }
                    }
                    if (!flag_save)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("工序存在特征值全部为空，不允许保存！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    //特殊判断P31是否有尺寸
                    for (int s = 0; s < dtFeature_Values.Rows.Count; s++)
                    {
                        string sFeatureName = dtFeature_Values.Rows[s]["FEATURE_NAME"].ToString();
                        if (sFeatureName == "P31_电子锯开料")
                        {
                            DataTable dtSize = BaseBuildSql.GetDataTableBySql(" select WIDTH,HEIGHT FROM IE_Part_SizeParmList where PART_NO='" + StrPart_No + "'");
                            if (dtSize.Rows.Count > 0)
                            {
                                if (dtSize.Rows[0]["WIDTH"].ToString().Trim().Length <= 0 && dtSize.Rows[0]["HEIGHT"].ToString().Trim().Length <= 0)
                                {
                                    DevExpress.XtraEditors.XtraMessageBox.Show("尺寸参数【长】或【宽】未维护", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                            }
                            else
                            {
                                DevExpress.XtraEditors.XtraMessageBox.Show("尺寸参数未维护", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }

                    //按图纸号创建
                    if (txtPart_No.Text.Length <= 0 && StrDWG_No != "NIL")
                    {
                        string sql_Feature = @"select DWG_NO from IE_Part_FeatureList where DWG_NO='" + StrDWG_No + "'";
                        if (BaseBuildSql.GetDataTableBySql(sql_Feature).Rows.Count > 0)
                        {
                            if (ConfirmOK() == DialogResult.No)
                                return;

                            //更新【IE_Part_TaskList】的“计算标识”
                            string UpdateSql = @"update IE_Part_TaskList set CAL_FLAG='' where DWG_NO='" + StrDWG_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                            BaseBuildSql.ExecuteNonQuery(UpdateSql);

                        }
                        //删除所有未上传的数据
                        string DeleteSql = @"delete from IE_Part_FeatureList where DWG_NO='" + StrDWG_No + "' ";
                        BaseBuildSql.ExecuteNonQuery(DeleteSql);
                        //取得部件号
                        DataTable dtPartTemp = dtResult_R.Select("DWG_NO='" + StrDWG_No + "'").CopyToDataTable();
                        dtPartTemp = dtPartTemp.DefaultView.ToTable(true, "PART_NO");
                        //得到该图纸号的所有部件号码
                        #region 注释
                        //for (int i = 0; i < dtPartTemp.Rows.Count; i++)
                        //{
                        //    for (int s = 0; s < dtFeature_Values.Rows.Count; s++)
                        //    {
                        //        //单独计算D34工时
                        //        if (dtFeature_Values.Rows[s]["PROCESS_CODE"].ToString() == "D34")
                        //        {

                        //            DataRow dr = dtTempList.NewRow();
                        //            dr["DWG_NO"] = StrDWG_No;
                        //            dr["PART_NO"] = dtPartTemp.Rows[i]["PART_NO"].ToString();
                        //            dr["PROCESS_CODE"] = dtFeature_Values.Rows[s]["PROCESS_CODE"].ToString();
                        //            dr["FEATURE_NAME"] = dtFeature_Values.Rows[s]["FEATURE_NAME"].ToString();
                        //            dr["FEAT_VALUE"] = dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString().Length > 0 ? dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString() : "";
                        //            if (dtFeature_Values.Rows[s]["FEATURE_NAME"].ToString() == "D34_部件类型")
                        //            {
                        //                //得到宽放系数
                        //                DataTable dtFactor = Common.GetCommon.GetWorkCenter_AllowanceFactor();
                        //                //得到该号码【D34】尺寸参数
                        //                DataTable dtSize = Common.GetCommon.GetSizeParmList(StrDWG_No, dtPartTemp.Rows[i]["PART_NO"].ToString());
                        //                //得到该号码单位工时和附加工时
                        //                DataTable dtWorkHours = Common.GetCommon.GetFeature_Definatian();
                        //                if (dtSize.Rows.Count <= 0)
                        //                    dr["LABOR_VALUE"] = "没有维护尺寸参数";
                        //                else if (dtWorkHours.Rows.Count <= 0)
                        //                    dr["LABOR_VALUE"] = "没有维护特征定义表";
                        //                else
                        //                {
                        //                    double TD34 = Math.Ceiling(LGC_VAL_D34.GetD34(dtFeature_Values.Select("PROCESS_CODE='D34'"),
                        //                   dtWorkHours.Select(),
                        //                        dtSize.Select())
                        //                        * (dtFactor.Select("PROCESS_CODE='D34'").Length <= 0 ? 1 :
                        //                     1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D34'"))[0].ItemArray[1].ToString()
                        //                        )));
                        //                    dr["LABOR_VALUE"] = TD34;
                        //                }
                        //            }
                        //            else
                        //                dr["LABOR_VALUE"] = 0;
                        //            dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        //            dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                        //            dtTempList.Rows.Add(dr);
                        //        }
                        //        else
                        //        {
                        //            //生成实际数据表
                        //            DataRow dr = dtTempList.NewRow();
                        //            dr["DWG_NO"] = StrDWG_No;
                        //            dr["PART_NO"] = dtPartTemp.Rows[i]["PART_NO"].ToString();
                        //            dr["PROCESS_CODE"] = dtFeature_Values.Rows[s]["PROCESS_CODE"].ToString();
                        //            dr["FEATURE_NAME"] = dtFeature_Values.Rows[s]["FEATURE_NAME"].ToString();
                        //            dr["FEAT_VALUE"] = dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString().Length > 0 ? dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString() : "";
                        //            //dr["LABOR_VALUE"] = dtFeature_Values.Rows[s]["LABOR_VALUE"].ToString().Length > 0 ? dtFeature_Values.Rows[s]["LABOR_VALUE"].ToString() : "0";
                        //            //因存在每个部件号可能有不同的工时，故需要重新计算
                        //            dr["LABOR_VALUE"] = Again_Cal_WorkHours(StrDWG_No, dtPartTemp.Rows[i]["PART_NO"].ToString(),
                        //                dtFeature_Values.Rows[s]["FEATURE_NAME"].ToString(),
                        //                dtFeature_Values.Rows[s]["PROCESS_CODE"].ToString(),
                        //                dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString().Length > 0 ? dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString() : "");
                        //            dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        //            dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName; ;
                        //            dtTempList.Rows.Add(dr);
                        //        }
                        //    }

                        //}
                        #endregion
                        //生成保存的特征数据表
                        dtTempList = Common.SaveFeat_Table.GetDataTable_Feat(dtPartTemp, dtFeature_Values, dtFeature_Def, StrDWG_No);
                        //批量插入数据库
                        if (BaseBuildSql.ExcuteInsert(dtTempList, "IE_Part_FeatureList"))
                        {
                            //更新【IE_Part_TaskList】的“特征录入标识”
                            bool update_Flag = true;
                            //如果存在错误代码，则不更新标识
                            for (int i = 0; i < dtTempList.Rows.Count; i++)
                            {
                                double V = Convert.ToDouble(dtTempList.Rows[i]["LABOR_VALUE"].ToString());
                                if (V == 900000 || V == 900001 || V == 900002 || V == 900003
                                   || V == 900004 || V == 900005 || V == 900006 || V == 900007
                                   || V == 900008 || V == 900009)
                                {
                                    update_Flag = false;
                                    break;
                                }

                            }
                            if (update_Flag)
                            {
                                string UpdateSql = "";
                                if (StrDWG_No == "NIL" || string.IsNullOrEmpty(StrDWG_No))
                                {
                                    UpdateSql = @"update IE_Part_TaskList set FEAT_FLAG='1' where PART_NO='" + StrPart_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                                }
                                else
                                {
                                    UpdateSql = @"update IE_Part_TaskList set FEAT_FLAG='1' where DWG_NO='" + StrDWG_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                                }
                                BaseBuildSql.ExecuteNonQuery(UpdateSql);
                                DevExpress.XtraEditors.XtraMessageBox.Show("数据保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                DevExpress.XtraEditors.XtraMessageBox.Show("失败！尺寸参数未维护！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }

                        }
                        else
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("数据保存失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }

                    //按部件编号创建
                    else
                    {
                        if (StrDWG_No != "NIL")
                        {
                            //如果该部件号的图纸不存在特征表，则不允许保存
                            string sql_Feature = @"select DWG_NO from IE_Part_FeatureList where PART_NO='" + txtPart_No.Text + "'";
                            if (BaseBuildSql.GetDataTableBySql(sql_Feature).Rows.Count <= 0)
                            {
                                DevExpress.XtraEditors.XtraMessageBox.Show("该部件号的图纸不存在特征清单，不允许保存，请先按图纸号创建特征！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                        }
                        //删除所有未上传的数据
                        string DeleteSql = @"delete from IE_Part_FeatureList where PART_NO='" + StrPart_No + "' ";
                        BaseBuildSql.ExecuteNonQuery(DeleteSql);
                        //取得部件号
                        DataTable dtPartTemp = dtResult_R.Select("PART_NO='" + StrPart_No + "'").CopyToDataTable();
                        dtPartTemp = dtPartTemp.DefaultView.ToTable(true, "PART_NO");
                        //得到该图纸号的所有部件号码
                        #region
                        //for (int i = 0; i < dtPartTemp.Rows.Count; i++)
                        //{
                        //    for (int s = 0; s < dtFeature_Values.Rows.Count; s++)
                        //    {
                        //        //单独计算D34工时
                        //        if (dtFeature_Values.Rows[s]["PROCESS_CODE"].ToString() == "D34")
                        //        {

                        //            DataRow dr = dtTempList.NewRow();
                        //            dr["DWG_NO"] = StrDWG_No;
                        //            dr["PART_NO"] = dtPartTemp.Rows[i]["PART_NO"].ToString();
                        //            dr["PROCESS_CODE"] = dtFeature_Values.Rows[s]["PROCESS_CODE"].ToString();
                        //            dr["FEATURE_NAME"] = dtFeature_Values.Rows[s]["FEATURE_NAME"].ToString();
                        //            dr["FEAT_VALUE"] = dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString().Length > 0 ? dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString() : "";
                        //            if (dtFeature_Values.Rows[s]["FEATURE_NAME"].ToString() == "D34_部件类型")
                        //            {
                        //                //得到宽放系数
                        //                DataTable dtFactor = Common.GetCommon.GetWorkCenter_AllowanceFactor();
                        //                //得到该号码【D34】尺寸参数
                        //                DataTable dtSize = Common.GetCommon.GetSizeParmList(StrDWG_No,dtPartTemp.Rows[i]["PART_NO"].ToString());
                        //                //得到该号码单位工时和附加工时
                        //                DataTable dtWorkHours = Common.GetCommon.GetFeature_Definatian();
                        //                if (dtSize.Rows.Count <= 0)
                        //                    dr["LABOR_VALUE"] = "没有维护尺寸参数";
                        //                else if (dtWorkHours.Rows.Count <= 0)
                        //                    dr["LABOR_VALUE"] = "没有维护特征定义表";
                        //                else
                        //                {
                        //                    double TD34 = Math.Ceiling(LGC_VAL_D34.GetD34(dtFeature_Values.Select("PROCESS_CODE='D34'"),
                        //                   dtWorkHours.Select(),
                        //                        dtSize.Select())
                        //                        * (dtFactor.Select("PROCESS_CODE='D34'").Length <= 0 ? 1 :
                        //                     1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D34'"))[0].ItemArray[1].ToString()
                        //                        )));
                        //                    dr["LABOR_VALUE"] = TD34;
                        //                }
                        //            }
                        //            else
                        //                dr["LABOR_VALUE"] = 0;
                        //            dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        //            dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                        //            dtTempList.Rows.Add(dr);
                        //        }
                        //        else
                        //        {
                        //            //插入数据库
                        //            DataRow dr = dtTempList.NewRow();
                        //            dr["DWG_NO"] = StrDWG_No;
                        //            dr["PART_NO"] = dtPartTemp.Rows[i]["PART_NO"].ToString();
                        //            dr["PROCESS_CODE"] = dtFeature_Values.Rows[s]["PROCESS_CODE"].ToString(); ;
                        //            dr["FEATURE_NAME"] = dtFeature_Values.Rows[s]["FEATURE_NAME"].ToString();
                        //            dr["FEAT_VALUE"] = dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString().Length > 0 ? dtFeature_Values.Rows[s]["FEAT_VALUE"].ToString() : "";
                        //            dr["LABOR_VALUE"] = dtFeature_Values.Rows[s]["LABOR_VALUE"].ToString().Length > 0 ? dtFeature_Values.Rows[s]["LABOR_VALUE"].ToString() : "0";
                        //            dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        //            dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName; ;
                        //            dtTempList.Rows.Add(dr);
                        //        }
                        //    }


                        //}
                        #endregion
                        //生成保存特征的数据表
                        dtTempList = Common.SaveFeat_Table.GetDataTable_Feat(dtPartTemp, dtFeature_Values, dtFeature_Def, StrDWG_No);
                        //批量插入数据库
                        if (BaseBuildSql.ExcuteInsert(dtTempList, "IE_Part_FeatureList"))
                        {
                            ////更新【IE_Part_TaskList】的“特征录入标识”
                            //string UpdateSql = @"update IE_Part_TaskList set FEAT_FLAG='1' where PART_NO='" + StrPart_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                            //BaseBuildSql.ExecuteNonQuery(UpdateSql);
                            //DevExpress.XtraEditors.XtraMessageBox.Show("数据保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            //更新【IE_Part_TaskList】的“特征录入标识”
                            bool update_Flag = true;
                            //如果存在错误代码，则不更新标识
                            for (int i = 0; i < dtTempList.Rows.Count; i++)
                            {
                                double V = Convert.ToDouble(dtTempList.Rows[i]["LABOR_VALUE"].ToString());
                                if (V == 900000 || V == 900001 || V == 900002 || V == 900003
                                   || V == 900004 || V == 900005 || V == 900006 || V == 900007
                                   || V == 900008 || V == 900009)
                                {
                                    update_Flag = false;
                                    break;
                                }

                            }
                            if (update_Flag)
                            {
                                string UpdateSql = @"update IE_Part_TaskList set FEAT_FLAG='1' where PART_NO='" + StrPart_No + "' and  ISNULL(UPLOAD_FLAG,'')!='1'";
                                BaseBuildSql.ExecuteNonQuery(UpdateSql);
                                DevExpress.XtraEditors.XtraMessageBox.Show("数据保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                DevExpress.XtraEditors.XtraMessageBox.Show("失败！尺寸参数未维护！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("数据保存失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }

                    }

                    //初始化
                    dtFeature_Values = Common.GetTable.GetCache_Feature();
                    // txtProductItem_UcTextChanged(null, null);
                    Init();
                    memoDWG_NO.Text = "";
                    //解锁当前录入员的操作图纸
                    Common.GetLock.UnLock();
                    FLAG_CellValueChanged = true;//初始化特征值改变标识
                    listTemp = new List<string>(); //获取上一次点击的值初始化
                    GetPartFeature();//重新刷新
                }
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);
            }
        }
        [DllImport("kernel32.dll")]
        private static extern bool SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
        //关闭
        private void Frm_IE_PartFeature_FormClosing(object sender, FormClosingEventArgs e)
        {
            //解除当前用户锁定的图号
            Common.GetLock.UnLock();
            //重新刷新内存
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
            }
        }
        //查询
        public override void DoView(IButtonInfo sender)
        {
            GetPartFeature();
            gvPart_List_Click(null, null);
        }
        public void GetPartFeature()
        {
            //SplashScreenTool.ShowSplashScreen(typeof(WaitForm1));
            string sql_DwgNo = "", sql_PartNo = "";
            StringBuilder sbDRAWING = new StringBuilder();
            StringBuilder sbPARTNO = new StringBuilder();
            string[] str1 = memoDWG_NO.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            string[] str2 = txtPart_No.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            if (str1[0].Length > 0)
            {
                sbDRAWING.AppendFormat(" AND T.DWG_NO IN('{0}') ", string.Join("','", str1.ToArray()));
                sql_DwgNo = sbDRAWING.ToString();
            }
            else
            {
                sql_DwgNo = "and T.DWG_NO like '%%'";
            }
            if (str2[0].Length > 0)
            {
                sbPARTNO.AppendFormat(" AND T.PART_NO IN('{0}') ", string.Join("','", str2.ToArray()));
                sql_PartNo = sbPARTNO.ToString();
            }
            else
            {
                sql_PartNo = "and T.PART_NO like '%%'";
            }
            string sql_Pro = txtProductItem.Text.Length > 0 ? " and T.PROD_CATEGORY='" + txtProductItem.Text + "'" : " and T.PROD_CATEGORY like '%%'";
            // string sql_PartNo = txtPart_No.Text.Length > 0 ? " and T.PART_NO='" + txtPart_No.Text + "'" : " and T.PART_NO like '%%'";
            string sql = sql_Pro + sql_DwgNo + sql_PartNo;

            // DataTable dtResult_R = new DataTable();
            //获取清单列表工艺路线标识为1的数据
            DataTable dtList = Common.GetDWG_List.Dwg_List("IE_Part_TaskList T LEFT jOIN IE_Part_MasterData M ON T.PART_NO=M.PART_NO",
                "distinct T.DWG_NO,T.PART_NO,M.CN_DESC,M.EN_DESC,REF_DWG,REF_MAT,M.MODEL_NO",
                " " + sql + " and ISNULL(T.DWG_NO,'')!='NIL'  and ISNULL(T.ROUTING_FLAG,'')='1' and ISNULL(T.FEAT_FLAG,'')!='1' and ISNULL(T.UPLOAD_FLAG,'')!='1' and ISNULL(T.DWG_NO,'')!='' and M.MRP_CONTROLLER not in ('WG1','PG1') and ISNULL(T.LOCK_FLAG,'')!='1' ");
            //获取工艺路线表上载标识为1的数据
            DataTable dtRouting = Common.GetDWG_List.Dwg_List(@"IE_Part_Routing R JOIN IE_Part_TaskList T on R.DWG_NO=T.DWG_NO and R.PART_NO=T.PART_NO JOIN IE_Part_MasterData M ON M.PART_NO=T.PART_NO JOIN IE_Part_FeatureList F ON F.PART_NO=R.PART_NO AND F.DWG_NO=R.DWG_NO",
                "distinct T.DWG_NO,T.PART_NO,M.CN_DESC,M.EN_DESC,T.REF_DWG,T.REF_MAT,M.MODEL_NO",
                " " + sql + " and ISNULL(T.DWG_NO,'')!='NIL' and ISNULL(T.ROUTING_FLAG,'')='1' and ISNULL(R.DWG_NO,'')!='' and ISNULL(T.UPLOAD_FLAG,'')!='1' and M.MRP_CONTROLLER not in ('WG1','PG1') and ISNULL(T.LOCK_FLAG,'')!='1' ");
            //获取已维护组件工艺路线未上载工时的物料清单
            DataTable dtRouting2 = Common.GetDWG_List.Dwg_List(@"IE_Part_Routing R JOIN IE_Part_TaskList T on  R.PART_NO=T.PART_NO JOIN IE_Part_MasterData M ON M.PART_NO=T.PART_NO",
                "distinct T.DWG_NO,T.PART_NO,M.CN_DESC,M.EN_DESC,T.REF_DWG,T.REF_MAT,M.MODEL_NO",
                " " + sql_Pro + sql_PartNo + "  and ISNULL(T.ROUTING_FLAG,'')='1' and (ISNULL(R.DWG_NO,'')='' or R.DWG_NO='NIL') and ISNULL(T.UPLOAD_FLAG,'')!='1' and M.MRP_CONTROLLER not in ('WG1','PG1') and ISNULL(T.LOCK_FLAG,'')!='1' ");

            //部件检查
            if (FLAG_TYPE == 1)
                dtResult_R = dtRouting;
            //BOM-组件检查
            if (FLAG_TYPE == 2)
                dtResult_R = dtRouting2;
            //部件创建
            if (FLAG_TYPE == 3)
                dtResult_R = dtList;

            //无数据
            if (dtResult_R.Rows.Count <= 0)
            {
                SplashScreenTool.CloseSplashScreen();
                Init();
                return;
            }

            //若有重复项则去掉
            DataView dv = new DataView(dtResult_R);
            dv.Sort = "DWG_NO,PART_NO";
            DataTable dtResult = dv.ToTable(true, new[] { "DWG_NO", "PART_NO", "REF_DWG", "REF_MAT" });

            //按图纸编号创建
            if (FLAG_TYPE == 1 || FLAG_TYPE == 3)
            {
                this.DWG_NO.Visible = true;
                this.PART_NO.Visible = false;
                this.DWG_NO.VisibleIndex = 0;  //因上面组合去重，图纸号会出现重复，需再次去掉重复的图纸号
                DataTable Dis_Temp1 = dtResult.DefaultView.ToTable(true, new[] { "DWG_NO" });
                DataTable Dis_DWG = dtResult.Clone();
                for (int i = 0; i < Dis_Temp1.Rows.Count; i++)
                {
                    DataRow dr = Dis_DWG.NewRow();
                    dr["DWG_NO"] = Dis_Temp1.Rows[i]["DWG_NO"].ToString();
                    dr["PART_NO"] = dtResult.Select("DWG_NO='" + Dis_Temp1.Rows[i]["DWG_NO"].ToString() + "'").CopyToDataTable().Rows[0]["PART_NO"].ToString();
                    dr["REF_DWG"] = dtResult.Select("DWG_NO='" + Dis_Temp1.Rows[i]["DWG_NO"].ToString() + "'").CopyToDataTable().Rows[0]["REF_DWG"].ToString();
                    dr["REF_MAT"] = dtResult.Select("DWG_NO='" + Dis_Temp1.Rows[i]["DWG_NO"].ToString() + "'").CopyToDataTable().Rows[0]["REF_MAT"].ToString();
                    Dis_DWG.Rows.Add(dr);
                }
                gcPart_List.DataSource = Dis_DWG;
            }
            //按部件编号创建
            else
            {
                this.DWG_NO.Visible = false;
                this.PART_NO.Visible = true;
                this.PART_NO.VisibleIndex = 0;//因上面组合去重，图纸号会出现重复，需再次去掉重复的图纸号
                DataTable Dis_Temp1 = dtResult.DefaultView.ToTable(true, new[] { "PART_NO" });
                DataTable Dis_DWG = dtResult.Clone();
                for (int i = 0; i < Dis_Temp1.Rows.Count; i++)
                {
                    DataRow dr = Dis_DWG.NewRow();
                    dr["DWG_NO"] = dtResult.Select("PART_NO='" + Dis_Temp1.Rows[i]["PART_NO"].ToString() + "'").CopyToDataTable().Rows[0]["DWG_NO"].ToString();
                    dr["PART_NO"] = Dis_Temp1.Rows[i]["PART_NO"].ToString();
                    dr["REF_DWG"] = dtResult.Select("PART_NO='" + Dis_Temp1.Rows[i]["PART_NO"].ToString() + "'").CopyToDataTable().Rows[0]["REF_DWG"].ToString();
                    dr["REF_MAT"] = dtResult.Select("PART_NO='" + Dis_Temp1.Rows[i]["PART_NO"].ToString() + "'").CopyToDataTable().Rows[0]["REF_MAT"].ToString();
                    Dis_DWG.Rows.Add(dr);
                }
                gcPart_List.DataSource = Dis_DWG;
            }

            // SplashScreenTool.CloseSplashScreen();
        }
        private static RepositoryItemTextEdit _nullEdit;
        public static RepositoryItemTextEdit NullEdit
        {
            get
            {
                if (_nullEdit == null)
                {

                    _nullEdit = new RepositoryItemTextEdit();
                    _nullEdit.ReadOnly = true;
                    _nullEdit.CustomDisplayText += (sender, args) => args.DisplayText = Feature_Value;
                }
                return _nullEdit;
            }
        }

        private void rbPart_No_C_CheckedChanged(object sender, EventArgs e)
        {
            Check_Changed();
            SetPanelControl3();
        }
        private void rbPart_No_U_CheckedChanged(object sender, EventArgs e)
        {
            Check_Changed();
            SetPanelControl3();
        }

        private void rbBOM_U_CheckedChanged(object sender, EventArgs e)
        {
            Check_Changed();
            SetPanelControl3();
        }
        public void Check_Changed()
        {
            if (rbPart_No_U.Checked)//rbPart_No_U rbBOM_U
            {
                FLAG_TYPE = 1;
                rbPart_No_C.Checked = false;
                rbBOM_U.Checked = false;
                Init();
            }
            else if (rbBOM_U.Checked)
            {
                FLAG_TYPE = 2;
                rbPart_No_C.Checked = false;
                rbPart_No_U.Checked = false;
                Init();
            }
            else
            {
                FLAG_TYPE = 3;
                rbPart_No_U.Checked = false;
                rbBOM_U.Checked = false;
                Init();
            }
        }
        public void SetPanelControl3()
        {
            if (rbBOM_U.Checked)
            {
                gc_CurrentPart.Visible = false;
                gc_ReferencePart.Visible = false;
                gridControl1.Visible = true;
                gridControl1.Dock = DockStyle.Fill;
            }
            else
            {
                gc_CurrentPart.Visible = true;
                gc_ReferencePart.Visible = true;
                gridControl1.Visible = false;
            }
        }

        public DialogResult ConfirmOK()
        {
            return DevExpress.XtraEditors.XtraMessageBox.Show("当前图纸已经有部件维护过特征，强制保存将更改同图号所有部件数据，并无法恢复！,是否确认保存？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
        }
        public DialogResult ConfirmDelete()
        {
            return DevExpress.XtraEditors.XtraMessageBox.Show("上条数据暂未保存，是否保存？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }

        public override void DoPrint(IButtonInfo sender)
        {
            frmBatchUpdate frm = new frmBatchUpdate();
            frm.ShowDialog();
        }

        private void gc_PartFeature_MouseLeave(object sender, EventArgs e)
        {
            //SendKeys.Send("\n");          
        }

        private void gc_PartFeature_MouseMove(object sender, MouseEventArgs e)
        {
            //if (e.X > 0 && e.X < (this.gc_PartFeature.Size.Width) && e.Y > 0 && e.Y < (this.gc_PartFeature.Size.Height))
            //{
            //    //SendKeys.Send("\n");
            //}
            //else
            //{
            //    SendKeys.Send("\n");
            //}
        }

        private void panelControl2_MouseMove(object sender, MouseEventArgs e)
        {
            // SendKeys.Send("\n");
        }

        private void groupControl3_MouseMove(object sender, MouseEventArgs e)
        {
            //if ((e.X > groupControl3.Left) & (e.X < (groupControl3.Left + groupControl3.Width)) & (e.Y > groupControl3.Top) & e.Y < (groupControl3.Top + groupControl3.Height))
            //// if (e.X > 0 && e.X < (this.gridControl1.Size.Width) && e.Y > 0 && e.Y < (this.gridControl1.Size.Height))
            //{
            //}
            //else
            //{
            //    SendKeys.Send("\n");
            //}
        }
        //回车事件
        private void gv_PartFeature_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                gv_PartFeature_CellValueChanged(null, null);
            }
        }
        //复制ctrl+c
        private void gvPart_List_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control & e.KeyCode == Keys.C)
            {
                Clipboard.SetDataObject(gvPart_List.GetFocusedRowCellValue(gvPart_List.FocusedColumn));
                e.Handled = true;
            }
        }
        //获取部件特征所有部件号-去重
        public void GETPARTNO()
        {
            dtPARTNO = Common.GetDWG_List.Dwg_List("[LamexMESManager].[dbo].[IE_Part_FeatureList]", "DISTINCT PART_NO", "");
        }
        //行颜色变化
        private void gvPart_List_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            //组件维护
            if (FLAG_TYPE == 2)
            {
                string ColorPartNo = gvPart_List.GetRowCellValue(e.RowHandle, "PART_NO").ToString();
                if (!string.IsNullOrEmpty(ColorPartNo))
                {
                    if (dtPARTNO.Select("PART_NO='" + ColorPartNo + "'").Length > 0)
                        e.Appearance.BackColor = Color.GreenYellow;//改变背景色
                }
            }
        }
        /// <summary>
        /// 一个DataTable按另一个的某列排序
        /// </summary>
        /// <param name="tmpDt"></param>
        /// <param name="tmpDt2"></param>
        /// <returns></returns>
        private DataTable LinqSortDataTable(DataTable tmpDt, DataTable tmpDt2)
        {

            var query = (from item in tmpDt.AsEnumerable()
                         join item2 in tmpDt2.AsEnumerable()
                         on item.Field<string>("FEATURE_NAME") equals item2.Field<string>("FEATURE_NAME")
                         orderby item2.Field<string>("DISPLAY_SEQUENCE")
                         select item);
            return query.ToList().CopyToDataTable();
        }
        //显示tooltip
        private void gv_PartFeature_MouseMove(object sender, MouseEventArgs e)
        {
            // 获取鼠标焦点
            GridHitInfo hi = gv_PartFeature.CalcHitInfo(new Point(e.X, e.Y));
            if (hi.RowHandle < 0 || hi.Column == null || hi.HitTest != GridHitTest.RowCell)
            {
                _RowHandle = -1;
                return;
            }
            // 获取行
            DataRow row = gv_PartFeature.GetDataRow(hi.RowHandle);
            // 只有在特征值列的时候才显示ToolTip
            if (hi.Column.FieldName == "FEAT_VALUE" || hi.Column.FieldName == "FEATURE_NAME" || hi.Column.FieldName == "LABOR_VALUE")
            {
                // 创建ToolTip的数据显示,只有订单有备注的时候才显示ToolTip
                string tooltipText = row["FEATURE_NAME"].ToString();
                if (dtFeature_Def.Select("FEATURE_NAME='" + tooltipText + "'").Length > 0)
                    tooltipText = dtFeature_Def.Select("FEATURE_NAME='" + tooltipText + "'").CopyToDataTable().Rows[0]["FEATURE_DESC"].ToString();
                if (!string.IsNullOrEmpty(tooltipText))
                {
                    // 获取显示ToolTip事件实例
                    ToolTipControllerShowEventArgs args = CreateShowArgs(tooltipText);
                    // 设置ToolTip标题
                    args.Title = "提示：";
                    // 显示ToolTip 这里不可以用控件的坐标.要用屏幕的坐标Control.MousePosition
                    MainGvTool.ShowHint(args, System.Windows.Forms.Control.MousePosition);
                }
            }
        }
        /// <summary>
        /// 创建显示ToolTip事件实例
        /// </summary>
        /// <param name="tooltipText"></param>
        /// <returns></returns>
        private ToolTipControllerShowEventArgs CreateShowArgs(string tooltipText)
        {
            ToolTipControllerShowEventArgs args = MainGvTool.CreateShowArgs();
            args.ToolTip = tooltipText;
            return args;
        }
    }
}